import BaseController from '@/lib/base-controller';
import { POST, RequestMapping } from '@/lib/add-router';
// import auth from '@/lib/auth'

@RequestMapping('/api/role_menu')
export default class RoleMenuController extends BaseController {
  @POST('/addRoleMenu')
  async addRoleMenu() {
    try {
      const { ctx, service } = this;
      ctx.validate({
        roleId: 'number',
        menuId: 'number',
      });
      // const { roleId, menuId } = ctx.request.body;
      const roleMenu = await service.roleMenu.addRoleMenu(ctx.request.body);
      this.success({
        code: 0,
        msg: '添加成功',
        roleMenu,
      });
    } catch (e) {
      this.fail({
        code: 1,
        message: e,
      });
    }
  }

  @POST('/updateRoleMenu')
  async updateRoleMenu() {
    try {
      const { ctx, service } = this;
      ctx.validate({
        id: 'number',
        roleId: 'number',
        menuId: 'number',
      });
      //  const { id, roleId, menuId } = ctx.request.body;
      const roleMenu = await service.roleMenu.updateRoleMenu(ctx.request.body);
      this.success({
        code: 0,
        msg: '修改成功',
        roleMenu,
      });
    } catch (e) {
      this.fail({
        code: 1,
        message: e,
      });
    }

  }


  @POST('/getRoleMenuById')
  async getRoleMenuById() {
    try {
      const { ctx, service } = this;
      ctx.validate({
        roleId: 'number',
      });
      // const { roleId } = ctx.request.body;
      const roleMenu = await service.roleMenu.getRoleMenuById(ctx.request.body);
      this.success({
        code: 0,
        msg: '查询成功',
        roleMenu,
      });
    } catch (e) {
      this.fail({
        code: 1,
        message: e,
      });
    }
  }
  // getRoleMenuList
  @POST('/getRoleMenuList')
  async getRoleMenuList() {
    try {
      const { ctx, service } = this;
      ctx.validate({
        roleId: 'number',
      });
      // const { roleId } = ctx.request.body;
      const roleMenu = await service.roleMenu.getRoleMenuList();
      this.success({
        code: 0,
        msg: '查询成功',
        roleMenu,
      });
    } catch (e) {
      this.fail({
        code: 1,
        message: e,
      });
    }
  }
  // getRoleMenuListByRoleId
  @POST('/getRoleMenuListByRoleId')
  async getRoleMenuListByRoleId() {
    try {
      const { ctx, service } = this;
      ctx.validate({
        roleId: 'number',
      });
      // const { roleId } = ctx.request.body;
      const roleMenu = await service.roleMenu.getRoleMenuListByRoleId(ctx.request.body);
      this.success({
        code: 0,
        msg: '查询成功',
        roleMenu,
      });
    } catch (e) {
      this.fail({
        code: 1,
        message: e,
      });
    }
  }
  // getRoleMenuListByMenuId
  @POST('/getRoleMenuListByMenuId')
  async getRoleMenuListByMenuId() {
    try {
      const { ctx, service } = this;
      ctx.validate({
        menuId: 'number',
      });
      // const { menuId } = ctx.request.body;
      const roleMenu = await service.roleMenu.getRoleMenuListByMenuId(ctx.request.body);
      this.success({
        code: 0,
        msg: '查询成功',
        roleMenu,
      });
    } catch (e) {
      this.fail({
        code: 1,
        message: e,
      });
    }
  }
}
